USE [BSM]
GO
/****** Object:  View [dbo].[vw_VouchersDetail]    Script Date: 11/03/2024 09:28:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[vw_VouchersDetail]
AS
SELECT     dbo.VoucherDetails.VoucherID, dbo.Voucher.VoucherNo, dbo.Voucher.VoucherDate, dbo.Voucher.GroupID, dbo.VoucherDetails.AccountNo, dbo.Accounts.AccountTitle, SessionInfo_1.SessionTitle, 
                      dbo.VoucherDetails.Remarks, dbo.VoucherDetails.Amount AS Debit, 0 AS Credit, dbo.VoucherDetails.DrOrCr, dbo.VoucherDetails.VoucherDetailID, dbo.Voucher.Remarks AS MasterRemarks, 
                      dbo.Voucher.SessionID, dbo.Accounts.ParentAccount, dbo.Voucher.BankAccountID, ISNULL(dbo.Voucher.CustomerName, '') AS CustomerName, dbo.Voucher.Expense, dbo.Voucher.Discount, 
                      dbo.VoucherDetails.ItemID, dbo.VoucherDetails.Qty, dbo.VoucherDetails.Qty AS InQty, 0 AS OutQty, dbo.VoucherDetails.Rate, ISNULL(dbo.Groups.GroupName, '.') AS GroupName, 
                      dbo.VoucherDetails.PartyID, ISNULL(Accounts_1.AccountTitle, '') AS SubPartyName, dbo.Accounts.CellNo, dbo.Accounts.Phone, dbo.Accounts.AreaID, dbo.Area.RegionID
FROM         dbo.Accounts LEFT OUTER JOIN
                      dbo.Area ON dbo.Accounts.AreaID = dbo.Area.AreaID RIGHT OUTER JOIN
                      dbo.VoucherDetails LEFT OUTER JOIN
                      dbo.Accounts AS Accounts_1 ON dbo.VoucherDetails.PartyID = Accounts_1.AccountNo ON dbo.Accounts.AccountNo = dbo.VoucherDetails.AccountNo LEFT OUTER JOIN
                      dbo.Groups RIGHT OUTER JOIN
                      dbo.Voucher ON dbo.Groups.GroupID = dbo.Voucher.GroupID ON dbo.VoucherDetails.VoucherID = dbo.Voucher.VoucherID LEFT OUTER JOIN
                      dbo.SessionInfo AS SessionInfo_1 ON dbo.Voucher.SessionID = SessionInfo_1.SessionID
WHERE     (dbo.VoucherDetails.DrOrCr = N'Dr')
UNION ALL
SELECT     VoucherDetails_1.VoucherID, Voucher_1.VoucherNo, Voucher_1.VoucherDate, Voucher_1.GroupID, VoucherDetails_1.AccountNo, Accounts_1.AccountTitle, SessionInfo_1.SessionTitle, 
                      VoucherDetails_1.Remarks, 0 AS Debit, VoucherDetails_1.Amount AS Credit, VoucherDetails_1.DrOrCr, VoucherDetails_1.VoucherDetailID, Voucher_1.Remarks AS MasterRemarks, 
                      Voucher_1.SessionID, Accounts_1.ParentAccount, Voucher_1.BankAccountID, ISNULL(Voucher_1.CustomerName, '') AS CustomerName, Voucher_1.Expense, Voucher_1.Discount, 
                      VoucherDetails_1.ItemID, VoucherDetails_1.Qty, VoucherDetails_1.Qty AS InQty, 0 AS OutQty, VoucherDetails_1.Rate, ISNULL(Groups_1.GroupName, '.') AS GroupName, VoucherDetails_1.PartyID, 
                      ISNULL(Accounts_2.AccountTitle, '') AS SubPartyName, Accounts_1.CellNo, Accounts_1.Phone, Accounts_1.AreaID, Area_1.RegionID
FROM         dbo.Accounts AS Accounts_1 LEFT OUTER JOIN
                      dbo.Area AS Area_1 ON Accounts_1.AreaID = Area_1.AreaID RIGHT OUTER JOIN
                      dbo.VoucherDetails AS VoucherDetails_1 LEFT OUTER JOIN
                      dbo.Accounts AS Accounts_2 ON VoucherDetails_1.PartyID = Accounts_2.AccountNo ON Accounts_1.AccountNo = VoucherDetails_1.AccountNo LEFT OUTER JOIN
                      dbo.Groups AS Groups_1 RIGHT OUTER JOIN
                      dbo.Voucher AS Voucher_1 ON Groups_1.GroupID = Voucher_1.GroupID ON VoucherDetails_1.VoucherID = Voucher_1.VoucherID LEFT OUTER JOIN
                      dbo.SessionInfo AS SessionInfo_1 ON Voucher_1.SessionID = SessionInfo_1.SessionID
WHERE     (VoucherDetails_1.DrOrCr = N'Cr')


-----------------------------------------------------------------------------------------------------------------------

USE [BSM]
GO
/****** Object:  View [dbo].[VW_Vouchers]    Script Date: 11/03/2024 09:17:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[VW_Vouchers]
AS
SELECT     dbo.VoucherDetails.VoucherID, dbo.Voucher.VoucherDate, dbo.Voucher.VoucherNo, dbo.Voucher.SessionID, dbo.SessionInfo.SessionTitle, dbo.SessionInfo.SessionFrom, 
                      dbo.SessionInfo.SessionTo, dbo.SessionInfo.CurrentSession, dbo.Voucher.Remarks AS MasterRemarks, dbo.Voucher.ReadOnly, dbo.VoucherDetails.VoucherDetailID, dbo.VoucherDetails.AccountNo,
                       Accounts_1.AccountTitle, dbo.VoucherDetails.Remarks, CASE WHEN (dbo.VoucherDetails.DrOrCr = N'Dr') THEN dbo.VoucherDetails.Amount ELSE - 1 * dbo.VoucherDetails.Amount END AS Amount, 
                      CASE WHEN (dbo.VoucherDetails.DrOrCr = N'Dr') THEN dbo.VoucherDetails.Amount ELSE 0 END AS Debit, CASE WHEN (dbo.VoucherDetails.DrOrCr = N'Cr') 
                      THEN dbo.VoucherDetails.Amount ELSE 0 END AS Credit, dbo.VoucherDetails.DrOrCr, Accounts_1.ParentAccount, dbo.Voucher.BankAccountID, dbo.Voucher.LoginID, dbo.Employees.EmployeeName, 
                      dbo.Voucher.HostName, dbo.Voucher.EntryDateTime, Accounts_2.AccountTitle AS BankAccountTitle, dbo.VoucherDetails.Amount AS ActualAmount, dbo.Voucher.Expense, dbo.Voucher.Discount, 
                      dbo.Voucher.ModifyID, Employees_1.EmployeeName AS ModifyName, dbo.Voucher.ModifyHostName, dbo.Voucher.ModifyDateTime, dbo.VoucherDetails.ItemID, dbo.vw_Items.ItemCode, 
                      dbo.vw_Items.ItemName, dbo.vw_Items.ItemNameUrdu, dbo.VoucherDetails.Qty, dbo.VoucherDetails.Rate, dbo.vw_Items.GroupID, dbo.vw_Items.GroupName, dbo.Voucher.CustomerName, 
                      dbo.VoucherDetails.ComPercentD, dbo.VoucherDetails.ComAmountD, dbo.VoucherDetails.TotalAmountD, dbo.VoucherDetails.LotNo, Accounts_1.Remarks AS CustomerAddress, Accounts_1.CellNo, 
                      Accounts_1.Phone, Accounts_1.NameUrdu, dbo.Voucher.GroupID AS SubPartyID, ISNULL(dbo.Groups.GroupName, '.') AS SubGroupName, Accounts_1.AreaID, dbo.VoucherDetails.PartyID, 
                      ISNULL(dbo.Accounts.AccountTitle, '') AS SubPartyName, dbo.Accounts.AreaID AS Expr1, dbo.Area.RegionID
FROM         dbo.Area RIGHT OUTER JOIN
                      dbo.Accounts ON dbo.Area.AreaID = dbo.Accounts.AreaID RIGHT OUTER JOIN
                      dbo.VoucherDetails ON dbo.Accounts.AccountNo = dbo.VoucherDetails.PartyID LEFT OUTER JOIN
                      dbo.vw_Items ON dbo.VoucherDetails.ItemID = dbo.vw_Items.ItemID LEFT OUTER JOIN
                      dbo.Accounts AS Accounts_1 ON dbo.VoucherDetails.AccountNo = Accounts_1.AccountNo LEFT OUTER JOIN
                      dbo.Employees AS Employees_1 RIGHT OUTER JOIN
                      dbo.Accounts AS Accounts_2 RIGHT OUTER JOIN
                      dbo.Groups RIGHT OUTER JOIN
                      dbo.Voucher ON dbo.Groups.GroupID = dbo.Voucher.GroupID ON Accounts_2.AccountNo = dbo.Voucher.BankAccountID ON Employees_1.EmployeeID = dbo.Voucher.ModifyID LEFT OUTER JOIN
                      dbo.Employees ON dbo.Voucher.LoginID = dbo.Employees.EmployeeID ON dbo.VoucherDetails.VoucherID = dbo.Voucher.VoucherID LEFT OUTER JOIN
                      dbo.SessionInfo ON dbo.Voucher.SessionID = dbo.SessionInfo.SessionID
